package com.kitwee.serialport.data;


import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.migration.Migration;
import android.content.Context;

import com.kitwee.serialport.data.dao.SerialPortDao;
import com.kitwee.serialport.data.model.SerialPortData;

import android.support.annotation.NonNull;

@Database(entities = {SerialPortData.class}, version = 1)
public abstract class SerialPortDatabase extends RoomDatabase {

    private static SerialPortDatabase INSTANCE;

    private static final Object mLock = new Object();

    public static SerialPortDatabase getInstance(Context context) {
        synchronized (mLock) {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                        SerialPortDatabase.class, DB_NAME)
                        .addMigrations(MIGRATION_1_2).build();
            }
            return INSTANCE;
        }
    }

    public abstract SerialPortDao serialPortDao();


    private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {

        }
    };


    private static final String DB_NAME = "serial_port.db";


}
